/**
 * 
 */
package com.fangqk.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fangqk.service.LinkService;
import com.fangqk.service.impl.HtmlServiceImpl;
import com.fangqk.utils.Ret;
import com.fangqk.utils.redis.RedisUtils;

/**
 * @author G-Train
 *
 */
@Controller
@RequestMapping("/nav/link")
public class LinkController {

	@Autowired
	LinkService linkServiceImpl;

	@Autowired
	HtmlServiceImpl htmlServiceImpl;

	@Autowired
	RedisUtils redisUtils;

	@RequestMapping("/saveMyLinks")
	@ResponseBody
	public Ret saveMyLinks(HttpServletRequest request, HttpServletResponse response, String links, Integer userId) {
		int ret = linkServiceImpl.saveMyLinks(userId, links);
		if (ret == 1) {
			redisUtils.set(userId + "_link", links);
			return new Ret(Ret.SUCCESS, "保存成功！", null);
		}
		return new Ret(Ret.FAIL, "保存失败！", null);
	}

	@RequestMapping("/getHtmlTitle")
	@ResponseBody
	public Ret getHtmlTitle(HttpServletRequest request, HttpServletResponse response, String url) {
		String title = htmlServiceImpl.getHtmlTitle(url);
		if (title != null) {
			return new Ret(Ret.SUCCESS, "获取成功！", title);
		}
		return new Ret(Ret.FAIL, "获取失败！", null);
	}

}
